﻿using System;
using System.Linq.Expressions;
using FluentlyXml.Core.Deserialization;

namespace FluentlyXml.Core.DSL
{
	/// <summary> </summary>
	internal class PropertyDeserializationSpec<T> : TypeDeserializationSpec<T>, IPropertyDeserializationSpec<T>
	{
		private readonly Expression<Func<T, object>> _expression;
		private readonly IDeserializationConfig _config;

		public PropertyDeserializationSpec(Expression<Func<T, object>> expression, IDeserializationConfig config) : base(config)
		{
			_expression = expression;
			_config = config;
		}

		/// <summary> </summary>
		public ITypeDeserializationSpec<T> From(PropertyDeserializer selector)
		{
			_config.SetPropertyDeserializer(typeof (T), _expression.GetProperty(), selector);
			return this;
		}
	}
}